package com.zdft.promotion.common.util;

/**
 * 字符串补位工具
 * @author wcy
 * @date 2019/10/31
 **/
public class StringComplementUtil {
    public static final String SEPARATOR_NO_RL = "-";
    public static final String SEPARATOR_L = "-L";
    public static final String SEPARATOR_R = "-R";
    public static final int CPL_LFET = 1;
    public static final int CPL_RIGHT = 2;

    public static String addZeroForNum(String str, int strLength,Integer cpl) {
        int strLen = str.length();
        if (strLen < strLength) {
            while (strLen < strLength) {
                StringBuffer sb = new StringBuffer();
                if (cpl == CPL_LFET){
                    sb.append("0").append(str);// 左补0
                }else {
                    sb.append(str).append("0");//右补0
                }
                str = sb.toString();
                strLen = str.length();
            }
        }
        return str;
    }

    public static void main(String[] args) {
        System.out.println("args = [" + addZeroForNum("1",4,CPL_RIGHT) + "]");
    }

}
